# @Time  :2021/5/27 22:15
# @Author: Houtaroy
from datetime import datetime

from flask.json import JSONEncoder
from flask_sqlalchemy import Pagination


class KoalaJSONEncoder(JSONEncoder):
    def default(self, o):
        if isinstance(o, datetime):
            return str(round(o.timestamp()))
        if isinstance(o, Pagination):
            temp = o.__dict__
            del temp['query']
            temp['pages'] = o.pages
            return temp
        else:
            return super().default(o)
